#define WebView

using UnityEngine;
#if WebView && !UNITY_WEBGL
using Vuplex.WebView;
#endif
namespace CGF
{
    public static class WebViewHelper
    {
        public static async CTask<RectTransform> CreateWebView(string url, RectTransform parent)
        {
#if WebView && !UNITY_WEBGL
            CanvasWebViewPrefab webviewPrefab = CanvasWebViewPrefab.Instantiate();
            webviewPrefab.transform.SetParent(parent, false);
            webviewPrefab.Native2DModeEnabled = true;
            await webviewPrefab.WaitUntilInitialized();
            if (Application.isEditor)
            {
                Application.OpenURL(url);
            }
            else
            {
                webviewPrefab.WebView.LoadUrl(url);
            }
            return webviewPrefab.transform as RectTransform;
#else
            return null;
#endif
        }
    }
}
